import java.util.*;
import java.io.*;
public class Password {
    Scanner sc = new Scanner(System.in);
    //加密
    public void encrypt(){
        System.out.print("请输入要加密的数字密码：");
        String pwd1 = sc.next();
        char[] array=pwd1.toCharArray();     //获取字符数组
        for (int i = 0; i < array.length; i++) {     //遍历字符数组
            array[i]=(char)(((int)(array[i])+(i+1))+3);   //对每个数组元素进行加密运算
        }
        char temp=array[0];
        array[0]=array[array.length-1];
        array[array.length-1]=temp;     //将字符串的第一位和最后一位调换位置
        String str= new StringBuffer(new String(array)).reverse().toString();   //将字符串反转
        System.out.println("加密后的结果："+str);
        pressAnyKeyToContinue();
    }
    public void decrypt(){
        System.out.print("请输入要解密的数字密码：");
        String pwd2 = sc.next();
        String str1= new StringBuffer(pwd2).reverse().toString();   //先将字符串反转
        char[] array=str1.toCharArray();     //获取字符数组
        char temp=array[0];
        array[0]=array[array.length-1];
        array[array.length-1]=temp;     //将第一位和最后以为调换位置
        for (int i = 0; i < array.length; i++) {     //遍历字符数组
            array[i]=(char)(((int)(array[i])-(i+1))-3);   //对每个数组元素进行解密运算
        }
        String str2= new StringBuffer(new String(array)).toString();
        System.out.println("解密后的结果："+str2);
        pressAnyKeyToContinue();
    }

    public void pressAnyKeyToContinue(){
        System.out.println("按任意键返回");
        try {
            System.in.read();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
